<?php


namespace app\controller\admin\activity;

use app\common\model\activity\NewActivityCouponRelevance;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\product\SpuRepository;
use crmeb\basic\BaseController;
use app\common\repositories\article\ArticleCategoryRepository;
use app\common\repositories\article\ArticleContentRepository;
use app\common\repositories\activity\NewActivityProductRepository;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use app\validate\admin\ArticleValidate;

class NewActivityProduct extends BaseController
{
    /**
     * @var NewActivityProductRepository
     */
    protected $repository;

    /**
     * activity constructor.
     * @param App $app
     * @param NewActivityProductRepository $repository
     */
    public function __construct(App $app,NewActivityProductRepository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }

    /**
     * @return mixed
     * @author: fupeng
     * @day: 2024/1/28
     */
    public function getList()
    {
        [$page, $limit] = $this->getPage();

        $where = $this->request->params(['keyword','status','mer_name','new_activity_id']);

        return app('json')->success($this->repository->getAdminList($where, $page, $limit));
    }

    public function switchStatus($id)
    {
        $status = $this->request->param('status', 0) == 1 ? 1 : 0;
        if (!$ret = $this->repository->get($id))
            return app('json')->fail('数据不存在');
        if ($status == 0 && empty($data['msg']))
            return app('json')->fail('请填写下架理由');
        $this->repository->update($id, ['admin_status' => $status]);
        return app('json')->success('修改成功');
    }


    /**
     * @return mixed
     * @author: fupeng
     * @day: 2024/1/31
     * 审核
     */
    public function switchAudit()
    {
        $id = $this->request->param('id');
        if (!$this->repository->get($id))
            return  app('json')->fail('数据不存在');
        $data = $this->request->params(['status', 'msg']);
        if ($data['status'] == -1 && empty($data['msg']))
            return app('json')->fail('请填写拒绝理由');
        $this->repository->switchStatus($id,$data);
        return app('json')->success('操作成功');
    }

}
